<?php include('header.php');?>
<h1 class="pagetitle"><?php include('menu.php');?></h1>

<div id="page">
<!-- start content -->
	<div id="content" >		
		<form name="frmSalesOrder" action="" method="POST">
			<!-- <div style=" height:90%; overflow:auto;"> -->
			<table cellspacing="5" cellpadding="5" style="margin-left:-5px;margin-top:-5px;width:600px"  border='0'>	
				<TR width="100%" >
					<td class="headTDleft" colspan="7">
					<h2>Personal Sales Data</h2>
					</td>
				</TR>
				<TR>
					<td>
					<font color="red">
						<ul>
						<?php 
						if(count($errors) > 0){
							foreach($errors as $errorMsg){
								echo '<li>'.$errorMsg.'</li>';
							}
						}
						?>
						</ul>
					</font>
					</td>
				</TR>
				</table>
				<table cellspacing="0" cellpadding="0" width="85%"  style="margin-left:35px;margin-top:5px" border="0">
				<tr width="100%">
					<?php 
						if($viewAllSalesPersonsData == 1){
					?>
					<td>Region:</td>
					<td colspan='2'>						
						<select id="lstRegion" name="lstRegion">
							<option value="0">Please Select</option>
							<?php
								foreach($regionList as $key=>$value){
									$regionSel = '';
									if($regionId == $regionList[$key]['RegionID']){
										$regionSel = 'selected';
									}
							?>
							<option value="<?php echo $regionList[$key]['RegionID'];?>" <?php echo $regionSel;?>><?php echo $regionList[$key]['Name'];?></option>
							<?php 
								}
							?>
						</select>						
					</td>
					<?php
						}
					?>
					<td class="tdBold">Product:</td>
					<td colspan='2'>
						<select id="lstProduct" name="lstProduct" tabindex="0" >
							<option value="0">Please Select Product</option>
							<?php
								if(count($productList)){
									foreach($productList as $key=>$value){
										$prodSel = '';
										if($productId == $productList[$key]['ProductID']){
											$prodSel = 'selected';
										}
							?>
							<option value="<?php echo $productList[$key]['ProductID'];?>" <?php echo $prodSel;?>><?php echo $productList[$key]['Name'];?></option>
							<?php
								}
								}
							?>
						</select>
					</td>
					<td>&nbsp;&nbsp;&nbsp;
						<INPUT TYPE="SUBMIT" VALUE="Show Orders" ONCLICK="" class="button">&nbsp;
						<?php 
							if($viewAllSalesPersonsData == 0){
						?>
						<INPUT TYPE="button" VALUE="Add New Sales Order" ONCLICK="javascript:window.location='?a=2&b=1'" class="button" style="width:150px">
						<?php
						}
						?>					
					</td>
				</tr>
			</table>
			<br/>

			<div style="overflow:auto; width:100%; height: 575px;">
			<table cellspacing="0" cellpadding="0" width="90%" class="tableClass" style="margin-left:35px">
				<tr class="tableHeader" height="22px">
					<th class="tableTD">Sr. No</th>
					<th class="tableTD">Product Name</th>
					<th class="tableTD">Quantity</th>
					<th class="tableTD">Cost</th>
					<th class="tableTD">Order Date</th>
					<?php 
						if($viewAllSalesPersonsData == 0){
					?>
					<th class="tableTD">Action</th>
					<?php
						} else {
					?>
					<th class="tableTD">Region</th>
					<?php
						}
					?>
				</tr>
				<?php
					if (count($salesOrdersList) > 0){
						$recCount = 0;
						$i = 0;
						foreach ($salesOrdersList as $salesOrder){
							$recCount = $recCount + 1;
							$orderCost = $salesOrder['orderqty']*$salesOrder['cost'];
							if($i % 2 == 0){
								$tdClass = "tableTDAlt";
							} else {
								$tdClass = "tableTD";
							}
				?>
				<tr  height="20px">
					<td class="<?php echo $tdClass;?>" align="center"><?php echo $recCount;?></td>
					<td class="<?php echo $tdClass;?>">&nbsp;<?php echo $salesOrder['productname'];?>&nbsp;</td>
					<td class="<?php echo $tdClass;?>" align="right"><?php echo $salesOrder['orderqty'];?>&nbsp;</td>
					<td class="<?php echo $tdClass;?>" align="right"><?php echo $orderCost;?>&nbsp;</td>
					<td class="<?php echo $tdClass;?>" align="center"><?php echo substr($salesOrder['OrderDate'],0,10);?></td>
					<?php 
						if($viewAllSalesPersonsData == 0){
					?>
					<td align="center" class="<?php echo $tdClass;?>"><a href="?a=2&b=2&id=<?php echo $salesOrder['salesorderid'];?>">Edit</a></td>
					<?php
						} else {
					?>
					<td align="center" class="<?php echo $tdClass;?>"><?php echo $salesOrder['regionname'];?></td>
					<?php
					}
					?>
				</tr>			
				<?php						
							$i=$i+1;
						}
					} else {
				?>
				<tr class="tableHeader">
					<td colspan="6"></td>
				</tr>
				<tr>
					<td class="tableTDAlt" colspan="7" align="center" height="20px">Zero Sales Order found</td>
				</tr>
				<?php 
					}
				?>
			</table>
			</div>
			<!--table cellspacing="2" cellpadding="2" width="80%" border='0' style="margin-left:35px">
				<tr><td><br><INPUT TYPE="button" VALUE="Add New Sales Order" ONCLICK="javascript:window.location='?a=2&b=1'"><br><br></td></tr>
			</table-->
		</form>
	</div>
	<!-- end content -->
<?php include('auditLog.php');?>
<?php include('footer.php');?>